package cn.service.service.impl;

import cn.service.dao.OrderDao;
import cn.service.entiy.Goods;
import cn.service.entiy.Order;
import cn.service.entiy.User;
import cn.service.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDao orderDao;

    @Override
    public int buyGoods(Order order) {

        Goods goods=orderDao.getGoods(order.getGoodsId());
        order.setGoodsName(goods.getName());
        order.setPrice(goods.getPrice());

        User user=orderDao.getUser(order.getUserId());
        order.setUserMobile(user.getMobile());
        order.setUserAvatar(user.getAvatar());


        // 设置创建时间
        order.setCreateTime(new Date().getTime());

        // 总金额
        order.setAmount(order.getQuality()*goods.getPrice());

        int id=orderDao.insertOrder(order);
        System.out.println(id);
        return id;
    }

    @Override
    public ArrayList<Order> getBill(Long beginDate, Long endDate) {
        System.out.println(beginDate+"    "+endDate);
        return orderDao.getBill(beginDate,endDate);
    }
}
